package service

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"path/filepath"
)

func Upload(c *gin.Context) {

	file, err := c.FormFile("image")
	if err != nil {
		return
	}
	if file.Size > 5*1024*1024 {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "文件最大支持5GB",
		})
	}
	ext := filepath.Ext(file.Filename)
	if ext != ".mp4" && ext != ".avi" && ext != "mkv" {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "格式错误",
		})
	}
	err = c.SaveUploadedFile(file, "./upload/"+file.Filename)
	if err != nil {
		return
	}
	
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "图片上传成功",
	})
}
